Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

w: Implement PCPU and JCPU #53

Merged
merged 6 commits into from
Apr 13, 2024

Conversation

fortifiedhill
Copy link
Contributor

@fortifiedhill fortifiedhill commented Apr 5, 2024

The w manpage defines JCPU as the total CPU time of all processes under a given tty. The PCPU is defined as being the total time being used by the command in the "what" field.

For the JCPU implementation, the program creates a hashmap of all terminal numbers and their total time by walking the pid folders in /proc. I don't think this is terrible performance-wise, as execution time is still slightly faster than the original w, when built in release mode.

Total time for a process is calculated by taking the sum of time scheduled in both user mode and kernel mode and dividing that by the system's clock tick.

In terms of tests, I've added a couple of unit tests and updated the test_output_format to make sure the JCPU and PCPU fields are populated, these still need to be formatted, so the tests don't check for formatting.

The w manpage defines JCPU as the total CPU time of all processes under
a given tty. The PCPU is defined as being the total time being used
by the command in the "what" field.
@cakebaker
Copy link
Contributor

Did you see that some tests fail on macOS? It seems like there is no /proc on macOS.

Most functions and tests have been enabled only on Linux, as that's
the only platform that they were tested on.
Copy link

codecov bot commented Apr 6, 2024

Codecov Report

Attention: Patch coverage is 59.09091% with 18 lines in your changes are missing coverage. Please review.

Project coverage is 48.37%. Comparing base (6060b5e) to head (0a85e96).
Report is 3 commits behind head on main.

❗ Current head 0a85e96 differs from pull request most recent head d66c13d. Consider uploading reports for the commit d66c13d to get more accurate results

Files Patch % Lines
src/uu/w/src/w.rs 60.46% 6 Missing and 11 partials ⚠️
tests/by-util/test_w.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #53      +/-   ##
==========================================
- Coverage   49.44%   48.37%   -1.08%     
==========================================
  Files          15       15              
  Lines        1891     1933      +42     
  Branches      263      277      +14     
==========================================
  Hits          935      935              
- Misses        808      839      +31     
- Partials      148      159      +11     
Flag Coverage Δ
macos_latest 47.70% <ø> (-0.79%) ⬇️
ubuntu_latest 48.87% <59.09%> (+0.18%) ⬆️
windows_latest 0.12% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Only import crates when they're being used on a target platform.
@fortifiedhill
Copy link
Contributor Author

Did you see that some tests fail on macOS? It seems like there is no /proc on macOS.

Thanks, I've fixed the issue by only enabling /proc based functions on Linux, as I've only tested them there.

src/uu/w/src/w.rs Outdated Show resolved Hide resolved
src/uu/w/src/w.rs Outdated Show resolved Hide resolved
src/uu/w/src/w.rs Outdated Show resolved Hide resolved
Changed code based on code review from sylvestre.
@fortifiedhill
Copy link
Contributor Author

Thanks for the detailed and thorough code review sylvestre! I've tested the changes and have committed them.

@sylvestre
Copy link
Contributor

Could you please add the comments back?

I think your merge brings back the previous issue, the self?

@fortifiedhill
Copy link
Contributor Author

fortifiedhill commented Apr 10, 2024

Could you please add the comments back?

I think your merge brings back the previous issue, the self?

I removed the self, as was done in #54, to resolve the conflict, I think that's correct?

@sylvestre sylvestre merged commit c631ffe into uutils:main Apr 13, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants